<?php
namespace App\Http\Controllers\ShopApi\V1\Admin;

use App\Http\Controllers\ShopApiController;
use App\Http\Controllers\Business\Shop\V1\Admin\Admin;

class AdminController extends ShopApiController
{
    //管理列表
    public function adminList() {
        $shopUserId = $this->shopUserId;
        $shopId = $this->request->get('shopid');
        $versionCode = $this->request->get('versioncode');
//        if($versionCode >= 11) {
//            //新版本
//            $result = Admin::adminListByV12Version($shopId, $shopUserId);
//        } else {
//            //老版本
//            $result = Admin::adminList($shopId, $shopUserId);
//        }
        $result = Admin::adminList($shopId, $shopUserId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessData($result['data']);
        }
    }
    //增加用户
    public function addAdmin() {
        $shopUserId = $this->shopUserId;
        $shopId = $this->request->get('shopid');
        $mobile = $this->request->get('mobile');
        $name = $this->request->get('name');
        $auth = $this->request->get('auth');
        $code = $this->request->get('code');
        $result = Admin::addAdmin($shopId,$mobile,$name,$auth, $code, $shopUserId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    //详情
    public function adminDetail() {
        $shopId = $this->request->get('shopid');
        $mobile = $this->request->get('mobile');
        $result = Admin::adminDetails($shopId, $mobile);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessData($result['data']);
        }
    }
    //
    public function editAdmin() {
        $shopId = $this->request->get('shopid');
        $mobile = $this->request->get('mobile');
        $auth = $this->request->get('auth');
        $result = Admin::editAdmin($shopId, $mobile, $auth);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
    public function deleteAdmin() {
        $shopId = $this->request->get('shopid');
        $mobile = $this->request->get('mobile');
        $result = Admin::delAdmin($shopId,$mobile);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        } else {
            return $this->responseSuccessMessage($result['message']);
        }
    }
}